package com.zhilianbao.leyaogo.ui.adapter.search;

import android.content.Context;

import com.bql.baseadapter.recycleView.QuickRcvAdapter;
import com.bql.baseadapter.recycleView.QuickRcvHolder;
import com.zhilianbao.leyaogo.R;
import com.zhilianbao.leyaogo.listener.OnAddToCartClickListener;
import com.zhilianbao.leyaogo.model.response.category.GoodsInfo;
import com.zhilianbao.leyaogo.utils.ImageUtils;
import com.zhilianbao.leyaogo.utils.Utils;
import com.zhilianbao.leyaogo.view.widgets.MoneyTextView;

import java.util.List;

/**
 * ClassName: SearchAdapter <br>
 * Description: 搜索适配器<br>
 * Author: Cyarie <br>
 * Created: 2016/10/26 10:20 <br>
 * Update Time：<br>
 * Update Description：<br>
 */
public class SearchAdapter extends QuickRcvAdapter<GoodsInfo> {

    public SearchAdapter(Context context, List<GoodsInfo> data) {
        super(context, data, R.layout.item_search);
    }

    @Override
    protected void bindDataHelper(QuickRcvHolder viewHolder, int position, GoodsInfo item) {
        viewHolder.setText(R.id.tv_goods_name, item.getGoodsName());

        if (item.getGoodsType() == 1 && item.getGoodsSkuId() != 0) {
            viewHolder.setText(R.id.tv_goods_sku, item.getGoodsSkuName());
            ((MoneyTextView) viewHolder.getView(R.id.tv_account_price)).setAmount(item.getSkuPrice());
            ((MoneyTextView) viewHolder.getView(R.id.tv_origin_price)).setAmount(item.getSkuMPrice());
            viewHolder.setText(R.id.tv_goods_small, item.getItemVals());
        } else {
            viewHolder.setText(R.id.tv_goods_sku, "");
            ((MoneyTextView) viewHolder.getView(R.id.tv_account_price)).setAmount(item.getPrice());
            ((MoneyTextView) viewHolder.getView(R.id.tv_origin_price)).setAmount(item.getMPrice());
            viewHolder.setText(R.id.tv_goods_small, item.getGoodsDesc());
        }

        ImageUtils.loadGoodsPic(Utils.returnUrlShow(item.getGoodsPic()), viewHolder.getView(R.id.iv_goods_pic));
        viewHolder.getView(R.id.iv_add).setOnClickListener(v -> {
            if (mOnAddToCartClickListener != null) {
                mOnAddToCartClickListener.onAddToCartClick(item, viewHolder.getView(R.id.iv_goods_pic));
            }
        });
    }


    private OnAddToCartClickListener mOnAddToCartClickListener;

    public void setOnAddCartClickListener(OnAddToCartClickListener mOnAddToCartClickListener) {
        this.mOnAddToCartClickListener = mOnAddToCartClickListener;
    }

}
